Xbasic

SQL::ResultSetToJSONFile Method

Syntax

Result as L = toJSONFile(TargetFile as C [, RowsToCopy as N [, StartRow as N [, UpperCaseNames as L [, ConvertToText as L [, DateTimeFormat as C [, DateFormat as C [, ReferenceColumns as SQL::TableInfo [, UserContext as P]]]]]]]])

Arguments

TargetFileCharacter

The name of the file to store the JSON, including the file path.

RowsToCopyNumeric

number of rows to use

StartRowNumeric

first row to use

UpperCaseNamesLogical

Uppercase names if .T.

ConvertToTextLogical

If .T. (default) single-quote numeric and logical values

DateTimeFormatCharacter

Format string for dateTime values, as used by the time Function, e.g. "yyyy-MM-dd"

DateFormatCharacter

Format string for date values, as used by the time Function

ReferenceColumnsSQL::TableInfo

When data is formatted for a column in the result set: (1) if ReferenceColumns has a column with a matching name, that object will be used to format the data; (2) otherwise the ColumnInfo property of the result set is used to format the data.

UserContextPointer

The user context is passed into the evaluation of the expression when data is formatted.

Returns

ResultLogical

Returns .t. if the operation is successful. Otherwise, returns .f.. If the operation fails, the callResult of the ResultSet object will contain more information.

Description

Convert a ResultSet to JSON object and store in TargetFile

Discussion

The toJSONFile method converts the SQL::ResultSet object to JSON then saves it in the specified target file. For example:

Example

dim cn as SQL::Connection
cn.open("::Name::AADemo-Northwind")
if (cn.execute("SELECT * FROM customers") ) then
    dim filename as c = "C:\Users\YOUR_USER_NAME\Documents\results.js"
    cn.resultSet.ToJSONFile(filename)
    ' Display the JSON File:
    dim contents as c = FILE.to_string(filename)
    showvar(contents)
end if
cn.close()

See Also